import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;
import java.nio.file.Files;
import java.util.List;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Desc:
 * @Author: yanghongjun
 * @Date: 2024/8/8
 **/
public class excel {
    public static void main(String[] args) throws IOException {
        int[][] table = new int[89][89];
        for (int i = 0; i < table.length; i++) {
            for (int j = 0; j < table[i].length; j++) {
                table[i][j] = 4;
            }
        }
        File file = new File("nft.txt");
        List<String> list = Files.readAllLines(file.toPath());
        for (int y = 0; y < list.size(); y++) {
            String s = list.get(89 - y - 1);
            char[] charArray = s.toCharArray();
            for (int x = 0; x < charArray.length; x++) {
                char c = charArray[x];
                table[y][x] = Integer.parseInt(String.valueOf(c));
            }
        }
        FileInputStream in = new FileInputStream(new File("NFTLand.xlsx"));
        // 通过输入流读取指定的Excel文件
        XSSFWorkbook excel = new XSSFWorkbook(in);
        // 获取Excel文件的第一个Sheet页
        XSSFSheet sheet = excel.getSheetAt(0);
        int id = 1;
        for (int y = 0; y < table.length; y++) {
            int[] ints = table[y];
            for (int x = 0; x < ints.length; x++) {
                int type = ints[x];
                // 从第3行开始写
                XSSFRow row1 = sheet.getRow(id + 2);
                if (row1 == null) {
                    row1 = sheet.createRow(id + 2);
                }
                // 创建单元格并在单元格中设置值，单元格编号也是从0开始
                row1.createCell(0).setCellValue(id); // id
                row1.createCell(1).setCellValue(x + 1); // x
                row1.createCell(2).setCellValue(y + 1); // y
                row1.createCell(3).setCellValue(type); // 土地类型
                row1.createCell(4).setCellValue(10); // 价格写死10
                row1.createCell(5).setCellValue(100); // buff效果写死100
                id++;
            }
        }
        FileOutputStream out = new FileOutputStream(new File("NFTLand.xlsx"));
        // 通过输出流将内存中的Excel文件写入到磁盘上
        excel.write(out);
        // 关闭资源
        out.flush();
        out.close();
        excel.close();
        in.close();
    }

}
